package com.itheima.d2_collection_nesting;

import java.util.*;

/**
 * 目标：理解集合的嵌套。
 * 江苏省 = "南京市","扬州市","苏州市","无锡市","常州市"
 * 湖北省 = "武汉市","孝感市","十堰市","宜昌市","鄂州市"
 * 河北省 = "石家庄市","唐山市", "邢台市", "保定市", "张家口市"
 */
public class Test {
    public static void main(String[] args) {
        // 1、定义一个Map集合存储全部的省份信息，和其对应的城市信息。
        ArrayList<String> cities1 = new ArrayList<>();
        Collections.addAll(cities1,"南京市","扬州市","苏州市","无锡市","常州市");
        System.out.println("cities1 = " + cities1);

        ArrayList<String> cities2 = new ArrayList<>();
        Collections.addAll(cities2,"武汉市","孝感市","十堰市","宜昌市","鄂州市");

        ArrayList<String> cities3 = new ArrayList<>();
        Collections.addAll(cities3, "石家庄市", "唐山市", "邢台市", "保定市", "张家口市");

        //Map去保存省和对应的市的关系
        Map<String, ArrayList<String>> provinces = new HashMap<>();
        provinces.put("江苏省", cities1);
        provinces.put("湖北省", cities2);
        provinces.put("河北省", cities3);

        //遍历
        //获取所有的键（省）
        Set<String> province = provinces.keySet();
        //遍历省，通过省获取对应的市
        for (String p : province) {
            ArrayList<String> cities = provinces.get(p);
            System.out.println("省：" + p);
            for (String city : cities) {
                System.out.println(city);
            }
        }
    }
}
